package cn.edu.zjicm.wordsnet_d.BroadcastReceiver;

import cn.edu.zjicm.wordsnet_d.activity.LockActivity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.BatteryManager;

public class DateTimeReceiver extends BroadcastReceiver{
	//日期改变
	private static final String ACTION_DATE_CHANGED = Intent.ACTION_DATE_CHANGED;
	//时间改变
	private static final String ACTION_TIME_TICK = Intent.ACTION_TIME_TICK;
	//电量改变
	private static final String ACTION_BATTERY_CHANGED = Intent.ACTION_BATTERY_CHANGED;
	@Override
	public void onReceive(Context context, Intent intent) {
		// TODO Auto-generated method stub
		String action = intent.getAction();
		if(ACTION_DATE_CHANGED.equals(action)){
//			Log.d("Tag", "捕捉到日期变化");
			LockActivity.setDate();
		}else if(ACTION_TIME_TICK.equals(action)){
//			Log.d("Tag", "捕捉到时间变化");
			LockActivity.setTime();
			
		}else if(ACTION_BATTERY_CHANGED.equals(action)){
//			Log.d("Tag", "捕捉到电量变化");
			int status = intent.getIntExtra("status", 0);
			int level = intent.getIntExtra("level", 0);
			int scale = intent.getIntExtra("scale", 100);
			switch (status) {
			//充电中
			case BatteryManager.BATTERY_STATUS_CHARGING:
				String power = (level*100/scale)+"%";
				LockActivity.setPower(power);
//				Log.d("Tag", "现在充电");
				break;
			default:
//				Log.d("Tag", "进入default");
				LockActivity.setPower("");
				break;
			}
			
		}
	}

}
